package com.huaxin.device.mapping;

import com.huaxin.device.dto.enums.WaterproofGrade;
import com.huaxin.device.dto.request.ElectricalWellCreateReqDTO;
import com.huaxin.device.dto.request.ElectricalWellUpdateReqDTO;
import com.huaxin.device.models.ElectricalWell;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "spring")
public interface ElectricalWellMapping {

    @Mapping(target = "waterproofGrade", ignore = true)
    ElectricalWell toEntity(ElectricalWellCreateReqDTO in);

    @AfterMapping
    default void afterMapping(ElectricalWellCreateReqDTO in, @MappingTarget ElectricalWell entity) {
        if (in.getWaterproofGrade() != null) {
            entity.setWaterproofGrade(WaterproofGrade.of(in.getWaterproofGrade()));
        }
    }


    @Mapping(target = "waterproofGrade", ignore = true)
    void updateEntity(ElectricalWellUpdateReqDTO in, @MappingTarget ElectricalWell entity);

    @AfterMapping
    default void afterMapping(ElectricalWellUpdateReqDTO in, @MappingTarget ElectricalWell entity) {
        if (in.getWaterproofGrade() != null) {
            entity.setWaterproofGrade(WaterproofGrade.of(in.getWaterproofGrade()));
        }
    }
}